home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / etc / init.d / umountfs < prev    next >
Text File  |  2009-10-14  |  3KB  |  140 lines

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides:          umountfs
  4. # Required-Start:
  5. # Required-Stop:     umountroot
  6. # Default-Start:
  7. # Default-Stop:      0 6
  8. # Short-Description: Turn off swap and unmount all local file systems.
  9. # Description:
  10. ### END INIT INFO
  11.  
  12. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  13. . /lib/init/vars.sh
  14.  
  15. . /lib/lsb/init-functions
  16.  
  17. umask 022
  18.  
  19. do_stop () {
  20.     exec 9<&0 </proc/mounts
  21.  
  22.     PROTECTED_MOUNTS="$(sed -n '0,/^\/[^ ]* \/ /p' /proc/mounts)"
  23.     WEAK_MTPTS="" # be gentle, don't use force
  24.     REG_MTPTS=""
  25.     TMPFS_MTPTS=""
  26.     while read -r DEV MTPT FSTYPE REST
  27.     do
  28.         echo "$PROTECTED_MOUNTS" | grep -qs "^$DEV $MTPT " && continue
  29.         case "$MTPT" in
  30.           /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/dev/.static/dev|/proc/*|/sys|/lib/init/rw)
  31.             continue
  32.             ;;
  33.           /var/run)
  34.             continue
  35.             ;;
  36.           /var/lock)
  37.             continue
  38.             ;;
  39.         esac
  40.         case "$FSTYPE" in 
  41.           proc|procfs|linprocfs|devfs|sysfs|usbfs|usbdevfs|devpts)
  42.             continue
  43.             ;;
  44.           tmpfs)
  45.             TMPFS_MTPTS="$MTPT $TMPFS_MTPTS"
  46.             ;;
  47.           *)
  48.             if echo "$PROTECTED_MOUNTS" | grep -qs "^$DEV "; then
  49.                 WEAK_MTPTS="$MTPT $WEAK_MTPTS"
  50.             else
  51.                 REG_MTPTS="$MTPT $REG_MTPTS"
  52.             fi
  53.             ;;
  54.         esac
  55.     done
  56.  
  57.     exec 0<&9 9<&-
  58.     
  59.     #
  60.     # Make sure tmpfs file systems are umounted before turning off
  61.     # swap, to avoid running out of memory if the tmpfs filesystems
  62.     # use a lot of space.
  63.     #
  64.     if [ "$TMPFS_MTPTS" ]
  65.     then
  66.         if [ "$VERBOSE" = no ]
  67.         then
  68.             log_action_begin_msg "Unmounting temporary filesystems"
  69.             fstab-decode umount $TMPFS_MTPTS
  70.             log_action_end_msg $?
  71.         else
  72.             log_daemon_msg "Will now unmount temporary filesystems"
  73.             fstab-decode umount -v $TMPFS_MTPTS
  74.             log_end_msg $?
  75.         fi
  76.     fi
  77.  
  78.     #
  79.     # Deactivate swap
  80.     #
  81.     if [ "$VERBOSE" = no ]
  82.     then
  83.         log_action_begin_msg "Deactivating swap"
  84.         swapoff -a >/dev/null
  85.         log_action_end_msg $?
  86.     else
  87.         log_daemon_msg "Will now deactivate swap"
  88.         swapoff -a -v
  89.         log_end_msg $?
  90.     fi
  91.  
  92.     #
  93.     # Unmount local filesystems
  94.     #
  95.     if [ "$WEAK_MTPTS" ]; then
  96.         if [ "$VERBOSE" = no ]
  97.         then
  98.             log_action_begin_msg "Unmounting weak filesystems"
  99.             fstab-decode umount -f -r -d $WEAK_MTPTS
  100.             log_action_end_msg $?
  101.         else
  102.             log_daemon_msg "Will now unmount weak filesystems"
  103.             fstab-decode umount -f -v -r -d $WEAK_MTPTS
  104.             log_end_msg $?
  105.         fi
  106.     fi
  107.     if [ "$REG_MTPTS" ]
  108.     then
  109.         if [ "$VERBOSE" = no ]
  110.         then
  111.             log_action_begin_msg "Unmounting local filesystems"
  112.             fstab-decode umount -f -r -d $REG_MTPTS
  113.             log_action_end_msg $?
  114.         else
  115.             log_daemon_msg "Will now unmount local filesystems"
  116.             fstab-decode umount -f -v -r -d $REG_MTPTS
  117.             log_end_msg $?
  118.         fi
  119.     fi
  120. }
  121.  
  122. case "$1" in
  123.   start)
  124.     # No-op
  125.     ;;
  126.   restart|reload|force-reload)
  127.     echo "Error: argument '$1' not supported" >&2
  128.     exit 3
  129.     ;;
  130.   stop)
  131.     do_stop
  132.     ;;
  133.   *)
  134.     echo "Usage: $0 start|stop" >&2
  135.     exit 3
  136.     ;;
  137. esac
  138.  
  139. :
  140.